package bit.dao;

import java.io.InputStream;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.stereotype.Component;

@Component("memberDAO")
public class MemberDAOImpl implements MemberDAO{
	
	private SqlSessionFactory sqlMapper;
	
	public MemberDAOImpl() {
		try {
			String resource = "bit/mybatis/SqlMapConfig.xml";
			InputStream inputStream = Resources.getResourceAsStream(resource);
			sqlMapper = new SqlSessionFactoryBuilder().build(inputStream);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public List<MemberDTO> getAll() {
		SqlSession session = sqlMapper.openSession();
		List<MemberDTO> list = null;
		try {
			list = session.selectList("getAll");
			session.commit();
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			session.close();
		}
		return list;
	}

}
